export default {
	data() {
		return {
			userList: [], //列表数据 
			memberInfo: {},
			treeData: [],
			member_arr: [],
		};
	},
	created() {
		//加判断 编辑页来的，请求列表接口
		// #ifdef MP-WEIXIN
		if (wx.getUserProfile) this.canIUseGetUserProfile = true;
		// #endif
	},
	onLoad() {
		this.memberInfo = uni.getStorageSync(this.preutils.userinfo)
		this.getUserListData();
	},
	methods: {
		showEditBtn() {

		},
		showDelBtn() {

		},
		toEdit(e) {
			this.$util.redirectTo('/pages/mine/staff/my-staff-edit', e, null, 'obj');
		},
		toDel(e) {
			uni.showModal({
				title: '删除后无法回复',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						this.delLoadData(e);
					}
				}
			});
		},
		getGroupName(e) {
			if (e.group.length > 0) {
				return e.group[0].group_name;
			} else {
				return ''
			}
		},
		delLoadData(e) {
			this.http.sendRequest({
				api: this.api.mine.delMember,
				data: {
					id: e.id
				},
				success: res => {
					let msg = res.message;
					if (res.code == '1') {
						this.$util.showToastSuc(msg);
						this.getUserListData();
					} else {
						this.$util.showToastErr(msg);
					}
				},
				fail: res => {}
			});
		},
		getUserListData() {
			var data = {
				page: 1,
				page_size: 999,
			};
			this.http.sendRequest({
				api: this.api.mine.getAuthAllMember,
				data: data,
				success: res => {
					let msg = res.message;
					if (res.code == '1' && res.data) {
						this.member_arr = res.data.data;
						this.getTreeData()
					} else {
						this.$util.showToastErr(msg);
					}
				},
				fail: res => {}
			});
		},
		getTreeData() {
			this.http.sendRequest({
				api: this.api.mine.siteTreeList,
				data: {logistics_id: this.memberInfo.logistics_id},
				success: res => {
					if (res.code == '1') {
						this.treeData = res.data;
						this.userList = [];
						this.treeDataHeadle(this.treeData);
					}
				},
				fail: res => {
					console.log(res, '==fail')
				}
			});
		},

		treeDataHeadle(lists) {
			for (var i = 0; i < lists.length; i++) {
				var item = lists[i];
				for (var j = 0; j < this.member_arr.length; j++) {
					var citem = this.member_arr[j];
					if (item.site_id == citem.site_id) {
						this.userList.push(citem);
					}
				}
				if (item.childlist.length > 0) {
					this.treeDataHeadle(item.childlist);
				}
			}
		},
	}
};